//
//  UIImage+Extension.swift
//  weiBo
//
//  Created by apple on 16/5/21.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIImage {
    
    //等比压缩图片
    func scaleImageWithWidth(scaleWidth: CGFloat ) -> UIImage {
        //计算压缩后的高度
        let scaleHeight = scaleWidth / self.size.width * self.size.height
        
        //设置size的大小
        let size = CGSizeMake(scaleWidth, scaleHeight)
        
        //开启上下文
        UIGraphicsBeginImageContext(size)
        //把图片绘制到指定区域
        self.drawInRect(CGRect(origin: CGPointZero, size: size))
        //压缩图片
        let scaleImage = UIGraphicsGetImageFromCurrentImageContext()
        //关闭上下文
        UIGraphicsEndImageContext()
        
        //返回图片
        return scaleImage
    }


}
